package com.example.demo;

import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.LineCaptcha;
import cn.hutool.captcha.generator.MathGenerator;
import cn.hutool.captcha.generator.RandomGenerator;
import cn.hutool.core.lang.Console;

public class CaptchaTest {
    public static void main(String[] args) {
        //线条干扰验证码
        //确定验证码图片的长和宽 util属于工具包
        LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(200,100);
        //将图片保存在何处
        lineCaptcha.write("d:/line.png");
        //打印验证码
        Console.log(lineCaptcha.getCode());
        //验证图形验证码的有效性
        lineCaptcha.verify("1234");
        //创建验证码是否正确
        lineCaptcha.createCode();
        lineCaptcha.write("d:/line2.png");
        //
        Console.log(lineCaptcha.getCode());
        //
        lineCaptcha.verify("1234");

        RandomGenerator randomGenerator = new RandomGenerator("0123456789",4);
        LineCaptcha captcha = CaptchaUtil.createLineCaptcha(200,100);
        //随机数字生成
//        captcha.setGenerator(randomGenerator);
        //四则运算验证码
        captcha.setGenerator(new MathGenerator());
        captcha.write("d:/line2.png");
    }
}
